package com.leetcode.algorithm.y22.m06;

/**
 * 1678. 设计 Goal 解析器
 * 
 * https://leetcode.cn/problems/goal-parser-interpretation/
 * 
 * @author jie.deng
 *
 */
class Question1678Solution01 {

	public String interpret(String command) {
		int len = command.length();
		int idx = 0;
		StringBuilder builder = new StringBuilder(len);
		while (idx < len) {
			char ch = command.charAt(idx);
			if (ch == 'G') {
				builder.append(ch);
			} else if (ch == '(') {
				if (command.charAt(idx + 1) == ')') {
					idx++;
					builder.append('o');
				} else {
					idx += 3;
					builder.append("al");
				}
			}
			idx++;
		}
		return builder.toString();
	}

}